package 排灯节照明;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int N = 110;
    static long l,r;
    static String str;
    static int[] s = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        for (int cases = 1; cases <= T; cases++) {
            Arrays.fill(s, 0);
            str = in.next();
            l = in.nextLong();
            r = in.nextLong();
            for (int i = 0; i < str.length(); i++) {
                if (str.charAt(i) == 'B') {
                    s[i + 1]++;
                }
                s[i + 1] += s[i];
            }
            System.out.printf("Case #%d: %d\n", cases, sum(r) - sum(l - 1));
        }
    }

    private static long sum(long k) {
        int n = str.length();
        long x = k / n;
        return x * s[n] + s[(int) (k % n)];
    }
}
